package cn.visu.controller;


import cn.visu.bean.User;
import cn.visu.service.UserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 程振奇 on 2017/3/12.
 */

@RestController
public class HelloController {
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private UserService userService;

    @GetMapping("/hello/{id}/{name}")
    public List<User> listUser(@PathVariable Long id, @PathVariable String name) {
//            String id = request.getParameter("id");
//            String name = request.getParameter("name");
        log.info("id---" + id);
        log.info("name---" + name);
        log.debug("log4j2Test");
        return userService.listUser();
    }


    @PostMapping("/user/addUser")
    public Map<String, Object> addUser(User user) {
        Map<String, Object> jsonMap = new HashMap<String, Object>();
        jsonMap.put("isSuccess", true);
        user.setCreateTime(new Date());
        user.setPositionId(1);
        user.setType((short)0);
        user.setStatus(0);
        userService.insertUser(user);
        return jsonMap;
    }


}

